home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / gnu / gnulib / rcs4 / source / rcsfreez.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-02-07  |  5.9 KB  |  197 lines

  1. /* Copyright (C) 1982, 1988, 1989 Walter Tichy
  2.    Distributed under license by the Free Software Foundation, Inc.
  3.  
  4. This file is part of RCS.
  5.  
  6. RCS is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 1, or (at your option)
  9. any later version.
  10.  
  11. RCS is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with RCS; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  
  20. Report problems and direct all questions to:
  21.  
  22.     rcs-bugs@cs.purdue.edu
  23.  
  24. Although there's not much point for THIS file, as it is a rough translation
  25. of rcsfreeze.sh from Bourne shell script to C, by Nikki Locke.
  26. (nikki@cix.compulink.co.uk or nikki@compulink.co.uk if that fails)
  27.  
  28. */
  29.  
  30. #ifndef lint
  31. static char rcsid[]=
  32. "$Header: d:/rcs/rcs/rcsfreez.c 1.1 91/02/07 14:09:15 ROOT_DOS Exp $";
  33. #endif
  34. /*****************************************************************************
  35.  *      'rcsfreeze' has the purpose of assigning a symbolic revision
  36.  *      number to a set of RCS files, which form a valid configuration.
  37.  *
  38.  *      The idea is to run rcsfreeze each time a new version is checked
  39.  *      in. A unique symbolic revision number (C_[number], where number
  40.  *      is increased each time rcsfreeze is run) is then assigned to the most
  41.  *      recent revision of each RCS file of the main trunk.
  42.  *
  43.  *      If the command is invoked with an argument, then this
  44.  *      argument is used as the symbolic name to freeze a configuration.
  45.  *      The unique identifier is still generated
  46.  *      and is listed in the log file but it will not appear as
  47.  *      part of the symbolic revision name in the actual RCS file.
  48.  *
  49.  *      A log message is requested from the user which is saved for future
  50.  *      references.
  51.  *
  52.  *      The program works only on all RCS files at one time.
  53.  *      It is important that all changed files are checked in (there are
  54.  *      no precautions against any error in this respect).
  55.  *      file names:
  56.  *      rcsfreeze/version         for the version number
  57.  *      rscfreeze/log             for the log messages, most recent
  58.  *                                logmessage first.
  59.  * N.B. Under Unix, the file names are RCS/rcsfreeze.version and
  60.  *      RCS/rcsfreeze.log, but these are too long for DOS. The DOS
  61.  *      files have been placed in their own directory so that the afn
  62.  *      "RCS/*.*" still refers only to RCS source files
  63.  *****************************************************************************
  64.  */
  65.  
  66.  
  67. /* $Log:    rcsfreez.c $
  68.  * Revision 1.1  91/02/07  14:09:15  ROOT_DOS
  69.  * Initial revision
  70.  * 
  71.  */
  72.  
  73. #include <stdio.h>
  74. #include <string.h>
  75. #include <direct.h>
  76.  
  77. char *PROGNAME;
  78. int VERSIONNUMBER;
  79. char SYMREV[64], SYMREVNAME[64];
  80. FILE *fd, *fd2;
  81. char inpline[256], filename[128], revision[128];
  82. #define VERSIONFILE "rcsfreez/version"
  83. #define LOGFILE "rcsfreez/log"
  84. #define TEMPFILE "rcsfreez.tmp"
  85.  
  86. main(int argc,char **argv)
  87. {
  88.     mkdir("rcsfreez");
  89.     PROGNAME = strrchr(argv[0],'\\');
  90.     if(!PROGNAME)
  91.         PROGNAME = strrchr(argv[0],':');
  92.     if(PROGNAME)
  93.         PROGNAME++;
  94.     else
  95.         PROGNAME = argv[0];
  96. /*
  97.  * Get version no from rcsfreez.ver, and increment
  98.  */
  99.     fd = fopen(VERSIONFILE,"r");
  100.     if(fd)
  101.         {
  102.         fscanf(fd,"%d",&VERSIONNUMBER);
  103.         fclose(fd);
  104.         }
  105.     VERSIONNUMBER++;
  106.     fd = fopen(VERSIONFILE,"w");
  107.     fprintf(fd,"%d\n",VERSIONNUMBER);
  108.     fclose(fd);
  109.     sprintf(SYMREV,"C_%d",VERSIONNUMBER);
  110.     if(argc > 1)
  111.         strcpy(SYMREVNAME,argv[1]);
  112.     else
  113.         strcpy(SYMREVNAME,SYMREV);
  114.     printf("%s: symbolic revision number computed: \"%s\"\n",PROGNAME,SYMREV);
  115.     printf("%s: symbolic revision number used:     \"%s\"\n",PROGNAME,SYMREVNAME);
  116.     printf("%s: the two differ only when %s invoked with argument\n",PROGNAME,PROGNAME);
  117. /*
  118.  * Stamp the logfile. Because we order the logfile the most recent
  119.  * first we will have to save everything right now in a temporary file.
  120.  */
  121.     fd = fopen(TEMPFILE,"w");
  122.     fprintf(fd,"Version: %s(%s)\n",SYMREVNAME,SYMREV);
  123.     fprintf(fd,"-----------\n");
  124. /*
  125.  * Now ask for a log message, continously add to the log file
  126.  */
  127.     printf("%s: give log message, summarizing changes\n",PROGNAME);
  128.     printf("       (terminate with ^Z or single '.')\n");
  129.     printf(">> ");
  130.     fflush(stdout);
  131.     while(gets(inpline) && inpline[0] != 26 && strcmp(inpline,"."))
  132.         {
  133.         fprintf(fd,"%s\n",inpline);
  134.         printf(">> ");
  135.         fflush(stdout);
  136.         }
  137.     fprintf(fd,"-----------\n\n");
  138.     fd2 = fopen(LOGFILE,"r");
  139.     if(fd2)
  140.         {
  141.         while(fgets(inpline,256,fd2))
  142.             fputs(inpline,fd);
  143.         fclose(fd2);
  144.         }
  145.     fclose(fd);
  146. /*
  147.  * combine old and new logfiles
  148.  */
  149.     fd = fopen(LOGFILE,"w");
  150.     fd2 = fopen(TEMPFILE,"r");
  151.     while(fgets(inpline,256,fd2))
  152.         fputs(inpline,fd);
  153.     fclose(fd2);
  154.     fclose(fd);
  155.     unlink(TEMPFILE);
  156. /*
  157.  * Now the real work begins by assigning a symbolic revision number
  158.  * to each rcs file. Take the most recent version of the main trunk.
  159.  */
  160.     system("rlog -h rcs/*.* >" TEMPFILE);
  161.     fd = fopen(TEMPFILE,"r");
  162.     if(!fd)
  163.         {
  164.         fprintf(stderr,"rlog error\n");
  165.         exit(1);
  166.         }
  167.     while(fgets(inpline,256,fd))
  168.         {
  169.         if(!strncmp(inpline,"RCS file:",9))
  170.             {
  171.             char *s = strrchr(inpline,' ');
  172.             
  173.             filename[0] = 0;
  174.             if(s)
  175.                 sscanf(s,"%s",filename);
  176.             }
  177.         else if(filename[0] && !strncmp(inpline,"head:",5))
  178.             {
  179.             char *s = strchr(inpline,' ');
  180.             
  181.             if(s)
  182.                 {
  183.                 sscanf(s,"%s",revision);
  184.                 printf("%s: file name: \"%s\", Revision Number: %s\n",
  185.                     PROGNAME,filename,revision);
  186.                 sprintf(inpline,"rcs -q -n%s:%s %s",SYMREVNAME,revision,filename);
  187.                 system(inpline);
  188.                 }
  189.             filename[0] = 0;
  190.             }
  191.         }
  192.     fclose(fd);
  193.     unlink(TEMPFILE);
  194.     return 0;
  195. }
  196.  
  197.